var table_order_info={
        order_info_data : function(){return JSON.parse(getLocalInfo("table_order_info.html"))},
        length          : $("[id*='draggable_order_info_content_']").length,
        reloadLength    : function(){this.length = $("[id*='draggable_order_info_content_']").length},
        order_p_deptid	: "",
        order_p_audit   : 0,
        init            : function(){
            this.reloadLength();
            $($("[id*='draggable_order_info_content_']")[this.length-1]).find("span").text(this.order_info_data().text);
            
            $($("[id*='draggable_order_info_content_']")[this.length-1]).find("textarea").attr("name",this.order_info_data().name);
            
            this.qrcode();
            this.datetime();
            this.htmltype();
            this.bindevent();
            this.loadData();
            this.checkboxforAudit();
            this.custremark();
            //移动功能
            mydraggablehandler();
            localStorage.removeItem("table_order_info.html");
        },
        loadData:function(){
            setTimeout(function(){
            	if(!(basicDataFixed.order_no.startsWith("SC")||basicDataFixed.order_no.startsWith("BS"))){
            		alert("暂未获取订单编号,页面重新载入"+basicDataFixed.order_no);
            		window.location.reload();
            		return;
            	}
                $("[name='order_p_order_no']").val(basicDataFixed.order_no);
                $("[name='order_p_virtual_order_no']").val($("[name='order_p_order_no']").val());
                $("[name='order_p_order_no']").attr("readonly","readonly");
                $('#ewm_img').empty();
                $('#ewm_img').parent().find("span").empty();
                $('#ewm_img').qrcode({//生成二维码
                    render      : "canvas",
                    text        : qrcodeUrl+toUtf8(basicDataFixed.order_no),
                    render      : "canvas",//设置渲染方式
                    width       : $("#ewm_img").width(),     //设置宽度
                    height      : $("#ewm_img").height(),     //设置高度
                    typeNumber  : -1,      //计算模式
                    //correctLevel    : QRErrorCorrectLevel.H,//纠错等级
                    background      : "#ffffff",//背景颜色
                    //src: '../../../images/zfb_logo.jpg',
                    foreground      : "#000000" //前景颜色
                 });
                table_order_info.qrremotecode_byname();
            },3000)
        },
        bindevent:function(){
            //订单编号
            if($("[name='order_p_order_no']").length>0){
                $("[name='order_p_order_no']").unbind("blur");
                $("[name='order_p_order_no']").bind("blur",function(){
                    $('#ewm_img').empty();
                    $('#ewm_img').parent().find("span").empty();
                    $('#ewm_img').qrcode({//生成二维码
                        render      : "canvas",
                        text        : qrcodeUrl+toUtf8($(this).val()),
                        render      : "canvas",//设置渲染方式
                        width       : $("#ewm_img").width(),     //设置宽度
                        height      : $("#ewm_img").height(),     //设置高度
                        typeNumber  : -1,      //计算模式
                        //correctLevel    : QRErrorCorrectLevel.H,//纠错等级
                        background      : "#ffffff",//背景颜色
                        //src: '../../../images/zfb_logo.jpg',
                        foreground      : "#000000" //前景颜色
                     });
                })
                
                $("[name='order_p_order_no']").unbind("input propertychange");
                $("[name='order_p_order_no']").bind("input propertychange",function(){
                    $('#ewm_img').empty();
                    $('#ewm_img').parent().find("span").empty();
                    $('#ewm_img').qrcode({//生成二维码
                        render      : "canvas",
                        text        : qrcodeUrl+toUtf8($(this).val()),
                        render      : "canvas",//设置渲染方式
                        width       : $("#ewm_img").width(),     //设置宽度
                        height      : $("#ewm_img").height(),     //设置高度
                        typeNumber  : -1,      //计算模式
                        //correctLevel    : QRErrorCorrectLevel.H,//纠错等级
                        background      : "#ffffff",//背景颜色
                        //src: '../../../images/zfb_logo.jpg',
                        foreground      : "#000000" //前景颜色
                     });
                })
            }
            //接单价格
            $("[name='order_p_order_price']").unbind("blur");
            $("[name='order_p_order_price']").bind("blur",function(){
            	$(this).val($(this).val().replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'));     
            });
            //公司订单编号校验是否重复判断 order_p_order_no_comp
            $("[name='order_p_order_no_comp']").unbind("blur.ajax");
            $("[name='order_p_order_no_comp']").bind("blur.ajax",function(){
            	if($("[name='order_p_order_no_comp']").val().length<1){
            		return;
            	}
            	$.ajax({
                    type: 'POST',
                    url: serverUrl+"/order/getOrderList",
                    data:{"start":0,"length": 1,"order_p_order_no_sys":"","order_p_buss_no":"","order_p_print":"","order_p_product_no":"","order_p_order_no":$("[name='order_p_order_no_comp']").val(),"order_p_order_status":""},
                    success: function(data){
                     if(data.returnData.length>0){
                    	 alert("温馨提示:订单编号历史数据中已存在");
                     }
                    }
            	});
            });
            //公司订单编号
            $("[name='order_p_order_no_comp']").unbind("blur.nospace");
            $("[name='order_p_order_no_comp']").bind("blur.nospace",function(){
            	$(this).val($(this).val().replace(/[\r\n]/g,"").trim());       
            });
            //工厂型号
            $("[name='order_p_product_no']").unbind("blur.nospace");
            $("[name='order_p_product_no']").bind("blur.nospace",function(){
            	$(this).val($(this).val().replace(/[\r\n]/g,"").trim());     
            });
        },
        htmltype:function(){
            var html_type = this.order_info_data().html_type;
            var html_type_val = this.order_info_data().html_type_val;
            //select
            if("select"==html_type){
                $($("[id*='draggable_order_info_content_']")[this.length-1]).find(".right-div-comp-right-content").empty();
                var str="";
                $.each(html_type_val.split(","),function(index,value){
                     str+="<option value='"+value+"'>"+value+"</option>"
                });
                $($("[id*='draggable_order_info_content_']")[this.length-1]).find(".right-div-comp-right-content").append('<div class="mydraggablehandler"></div><select style="width:100%;height:100%;text-align:center;text-align-last: center;" name="'+this.order_info_data().name+'">'+str+'</select>');
            }
            if("selectonline"==html_type){
                $($("[id*='draggable_order_info_content_']")[this.length-1]).find(".right-div-comp-right-content").empty();
                $($("[id*='draggable_order_info_content_']")[this.length-1]).find(".right-div-comp-right-content").append('<div class="mydraggablehandler"></div><select class="selectonline" style="width:100%;height:100%;text-align:center;text-align-last: center;" name="'+this.order_info_data().name+'" onclick="table_order_info.selectonline(this)">'+str+'</select>');
                this.selectonlineByName(this.order_info_data().name);
            }
        },
        selectonline:function(self){//自动获取
        	$.ajax({
                type: 'POST',
                url: serverUrl+"/createOrder/selectOnlineByType",
                data: {
                	type:$(self).attr("name"),
                	order_p_deptid:($("[name='order_p_deptid']").length>0)?$("[name='order_p_deptid']").val():table_order_info.order_p_deptid
                },
                success: function(data){
                 if(!data.result){
                     show_error_dialog(data.info);
                     return;
                 }else{
                	 if(data.data==null){
                		 alert("请先设置");
                		 return;
                	 }
                	 var val=$("[name='"+$(self).attr("name")+"']").val();
                	 $("[name='"+$(self).attr("name")+"']").empty();
                	 for(i=0;i<data.data.length;i++){
                		 var disable_status=false;
                		 if(data.data[i].status==0){
                    		 $("[name='"+$(self).attr("name")+"']").append("<option processingObject="+data.data[i].processingObject+" disabled value="+data.data[i].id+">"+data.data[i].name+"</option>");
                		 }else{
                    		 $("[name='"+$(self).attr("name")+"']").append("<option processingObject="+data.data[i].processingObject+" value="+data.data[i].id+">"+data.data[i].name+"</option>");
                		 }
                	 }
                	 $("[name='"+$(self).attr("name")+"']").val(val);
                 }
                }
        	});
        },
        selectonlineOnChange:function(self){//selectonline onchange事件
        	if($(self).attr("name")=="order_p_deptid"){//生产部门修改了 生产车间需要联动
        		$("[name='order_p_product_work_no']").click();
        	}
        	if($(self).attr("name")=="order_p_product_work_no"){//生产车间修改 需要联动总投料数
        		tbsourcefactoryColresizeEvent.sumFeedTotalByMaterialType($(self).attr("processingobject"));
        	}
        },
        selectonlineByName:function(name){//第一次
        	$(".selectonline").unbind("change.my");
        	$(".selectonline").bind("change.my",function(){
        		table_order_info.selectonlineOnChange(this);
        	})
        	$.ajax({
                type: 'POST',
                url: serverUrl+"/createOrder/selectOnlineByType",
                data: {
                	type:name,
                	order_p_deptid:($("[name='order_p_deptid']").length>0)?$("[name='order_p_deptid']").val():table_order_info.order_p_deptid
                },
                success: function(data){
                 if(!data.result){
                     show_error_dialog(data.info);
                     return;
                 }else{
                	 if(data.data==null){
                		 alert("请先设置");
                		 return;
                	 }
                	 var val=$("[name='"+name+"']").val();
                	 $("[name='"+name+"']").empty();
                	 for(i=0;i<data.data.length;i++){
                		 var disable_status=false;
                		 if(data.data[i].status==0){
                    		 $("[name='"+name+"']").append("<option processingObject="+data.data[i].processingObject+" disabled value="+data.data[i].id+">"+data.data[i].name+"</option>");
                		 }else{
                    		 $("[name='"+name+"']").append("<option processingObject="+data.data[i].processingObject+" value="+data.data[i].id+">"+data.data[i].name+"</option>");
                		 }
                	 }
                	 $("[name='"+name+"']").val(val);
                 }
                }
        	});
        },
        selectonlineauto:function(){
        	$(".selectonline").each(function(){
        		table_order_info.selectonline(this);
        	})
        	$(".selectonline").unbind("change.my");
        	$(".selectonline").bind("change.my",function(){
        		table_order_info.selectonlineOnChange(this);
        	})
        },
        qrcode :function(){
            //二维码
            if(this.order_info_data().name.indexOf("qrcode")>-1){
                $($("[id*='draggable_order_info_content_']")[this.length-1]).find(".right-div-comp").empty();
                $($("[id*='draggable_order_info_content_']")[this.length-1]).find(".right-div-comp").html("<span style='color:gray'>请拖到合适位置,填写好【订单编号】二维码自动生成</span>");
                
                $($("[id*='draggable_order_info_content_']")[this.length-1]).find(".right-div-comp").append("<div style='width:90%;height:90%;border:0px solid red; position: absolute;margin:auto; top: 0;left: 0;right: 0;bottom: 0;' id='ewm_img'></div><img style='width:90%;height:90%;border:0px solid red; position: absolute;margin:auto; top: 0;left: 0;right: 0;bottom: 0;display:none' id='ewm_img_print'/>")
                
                if( $("[name='order_p_order_no']").length>0&&$("[name='order_p_order_no']").val().length>0){
                    $($("[id*='draggable_order_info_content_']")[this.length-1]).find(".right-div-comp").find("span").remove();
                    $('#ewm_img').qrcode({//生成二维码
                        render      : "table",
                        text        : qrcodeUrl+$("[name='order_p_order_no']").val(),
                        render      : "canvas",//设置渲染方式
                        width       : $("#ewm_img").width(),     //设置宽度
                        height      : $("#ewm_img").height(),     //设置高度
                        typeNumber  : -1,      //计算模式
                        //correctLevel    : QRErrorCorrectLevel.H,//纠错等级
                        background      : "#ffffff",//背景颜色
                        //src: '../../../images/zfb_logo.jpg',
                        foreground      : "#000000" //前景颜色
                     });
                }
                //banding resize事件 修改二维码
                table_order_info.resizeQrcode();
            }
            if(this.order_info_data().html_type.indexOf("qrremotecode_byname")>-1){
            	$($("[id*='draggable_order_info_content_']")[this.length-1]).find(".right-div-comp").empty();
                $($("[id*='draggable_order_info_content_']")[this.length-1]).find(".right-div-comp").append("<img class='qrremotecode_byname' html_type_val="+this.order_info_data().html_type_val+" src='' style='width:90%;height:90%;border:0px solid red; position: absolute;margin:auto; top: 0;left: 0;right: 0;bottom: 0;' />")
                this.qrremotecode_byname();
            }
        },
        qrremotecode_byname:function(){
        	$(".qrremotecode_byname").each(function(){
        		var qrcode_url=$("[name='"+$(this).attr("html_type_val")+"']").val();
        		console.info(serverUrl+"/utils/qrcode?qrcode_url="+qrcode_url);
        		$(this).attr("src",serverUrl+"/utils/qrcode?qrcode_url="+qrcode_url);
        	})
        },
        resizeQrcode:function(){
        	$("#ewm_img").parent().parent().parent().resize(function(){
        		table_order_info.reloadQrcode();
        	})
        },
        reloadQrcode:function(){
        	//二维码重新加载
            if( $("[name='order_p_order_no']").length>0&&$("[name='order_p_order_no']").val().length>0){
            	if($('#ewm_img').length>0){
            		$('#ewm_img').empty();
                    $('#ewm_img').parent().find("span").empty();
                    $('#ewm_img').qrcode({//生成二维码
                        render      : "table",
                        text        : qrcodeUrl+$("[name='order_p_order_no']").val(),
                        render      : "canvas",//设置渲染方式
                        width       : $("#ewm_img").width(),     //设置宽度
                        height      : $("#ewm_img").height(),     //设置高度
                        typeNumber  : -1,      //计算模式
                        //correctLevel    : QRErrorCorrectLevel.H,//纠错等级
                        background      : "#ffffff",//背景颜色
                        //src: '../../../images/zfb_logo.jpg',
                        foreground      : "#000000" //前景颜色
                     });
            	}
            }
            this.qrremotecode_byname();
        },
        checkboxforAudit:function(){
           if(this.order_info_data().name.indexOf("order_p_audit")>-1&&this.order_info_data().name!="order_p_auditor"&&this.order_info_data().name!="order_p_audit_time"){
                $($("[id*='draggable_order_info_content_']")[this.length-1]).find(".right-div-comp-right-content").empty();
                $($("[id*='draggable_order_info_content_']")[this.length-1]).find(".right-div-comp-right-content").append('<input type="checkbox" style="height:100%" name="order_p_audit"/> ')
            }
        },
        datetime:function(){
            //日期
            if(this.order_info_data().name.indexOf("time")>-1){
                $($("[id*='draggable_order_info_content_']")[this.length-1]).find("textarea").remove();
                $($("[id*='draggable_order_info_content_']")[this.length-1]).find("input").attr("name",this.order_info_data().name).show();
            }
        },
        custremark:function(){
        	if(this.order_info_data().name.indexOf("order_p_cust_remark")>-1){
        		$($("[id*='draggable_order_info_content_']")[this.length-1]).find("[class='right-div-comp-left-text']").removeClass("right-div-comp-left-text").addClass("right-div-comp-left-text-img");
        		$($("[id*='draggable_order_info_content_']")[this.length-1]).find("[class='right-div-comp-right-content']").removeClass("right-div-comp-right-content").addClass("right-div-comp-right-content-img");
        	}
        	this.orderPVirtualOrderNo();
        },//系统订单编号显示
        orderPVirtualOrderNo:function(){
        	if(this.order_info_data().name.indexOf("order_p_virtual_order_no")>-1){
        		$("[name='order_p_virtual_order_no']").val($("[name='order_p_order_no']").val())
        	}
        },
        readonly:function(){
        	$("[name='order_p_product_no']").unbind("click");
        	$("[name='order_p_product_no']").bind("click",function(){
        		console.info($(this).val().trim());
        		if($(this).val().trim().indexOf("库存单")>-1){
        			$(this).attr("readonly","readonly");
        		}else{
        			$(this).removeAttr("readonly");
        		}
        	})
        },
        checkOrderNoComp:function(){
        	//公司订单编号校验是否重复判断 order_p_order_no_comp
            $("[name='order_p_order_no_comp']").unbind("blur");
            $("[name='order_p_order_no_comp']").bind("blur",function(){
            	if($("[name='order_p_order_no_comp']").val().length<1){
            		return;
            	}
            	$.ajax({
                    type: 'POST',
                    url: serverUrl+"/order/getOrderList",
                    data:{"start":0,"length": 1,"order_p_order_no_sys":"","order_p_buss_no":"","order_p_print":"","order_p_product_no":"","order_p_order_no":$("[name='order_p_order_no_comp']").val(),"order_p_order_status":""},
                    success: function(data){
                     if(data.returnData.length>0){
                    	 alert("温馨提示:订单编号历史数据中已存在");
                     }
                    }
            	});
            });
        }
    }
/*事件绑定*/
/*table_order_info.init();*/
localStorage.removeItem("table_order_info.html");
if(table_order_info.order_info_data()){
    table_order_info.qrcode();
    table_order_info.datetime();
    table_order_info.htmltype();
    table_order_info.bindevent();
    table_order_info.checkboxforAudit();
    table_order_info.custremark();
}
table_order_info.loadData();
table_order_info.resizeQrcode();
table_order_info.selectonlineauto();
table_order_info.checkOrderNoComp();
$(".Wdate").attr("autocomplete","off");
